//
//  BankCardDetailInfoController.m
//  HuLaQuan
//
//  Created by hok on 1/21/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "BankCardDetailInfoController.h"

#import "BankCardDetailInfoCell.h"

//labels
#import "YuUserCellLabel.h"

//jumps

#import "DeleteCardCheckController.h"

@interface BankCardDetailInfoController ()<UIActionSheetDelegate>

@property (nonatomic,strong) NSMutableArray *items;

@end

static NSString * const BankCardDetailInfoCellIdentifier = @"BankCardDetailInfoCell";

@implementation BankCardDetailInfoController

- (NSDictionary *)cardInfo
{
    if (!_cardInfo) {
        _cardInfo =@{@"title":@"单笔",@"info":@"5万"};
    }
    return _cardInfo;
}
- (NSMutableArray *)items
{
    if (!_items) {
        _items = [[NSMutableArray alloc] init];
    }
    return _items;
}

- (void)setupUI
{
    [self setupNavBackButton];
    
    [self setupFooterForTableView];
    
    [self.tableView registerNib:[BankCardDetailInfoCell nib] forCellReuseIdentifier:BankCardDetailInfoCellIdentifier];
    
    self.title = @"银行卡详情";
    
    [self testData];
    
    [self createNavigationBarRightBarButtonItemWithTitle:@"编辑"];
}
- (void)rightAction
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"银行卡"
                                  delegate:self
                                  cancelButtonTitle:@"取消"
                                  destructiveButtonTitle:nil
                                  otherButtonTitles: nil];
    
   
        
    [actionSheet addButtonWithTitle:@"解除绑定"];
        
    
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [actionSheet showInView:self.view];
}
- (void)testData
{
    [self.items addObject:@{@"title":@"单笔",@"info":@"5万"}];
    [self.items addObject:@{@"title":@"单日",@"info":@"5万"}];
}

#pragma mark UITableViewDataSource

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return kNormalCellHeight;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.items.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 40;
    
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{
    
    CGRect frameRect = CGRectMake(25, 0, 200, 40);
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
    YuUserCellLabel *textSection = [[YuUserCellLabel alloc] initWithFrame:frameRect];
    textSection.text = @"限额表";
    [view addSubview:textSection];
    return view;
    
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    

    BankCardDetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:BankCardDetailInfoCellIdentifier
                                                           forIndexPath:indexPath];
    cell.titleLabel.text = self.items[indexPath.row][@"title"];
    
    if (indexPath.row == 0) {
        cell.infoLabel.text = ServerMoneyToShow(self.cardInfo[@"singleQuota"]) ;
    }else{
        cell.infoLabel.text = ServerMoneyToShow(self.cardInfo[@"dayQuota"]) ;
    }
//    cell.infoLabel.text = self.items[indexPath.row][@"info"];
    return cell;
    
    
    
    
    
}
#pragma mark - Action Sheet
//点击按钮时触发的方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
     NSLog(@"buttonIndex:%ld",buttonIndex);
   // _index = buttonIndex-1;
    if (buttonIndex != 0) {
        [self performSegueWithIdentifier:@"ShowCardCheckFromCardInfo" sender:self];
    }
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    
    if ([[segue identifier] isEqualToString:@"ShowCardCheckFromCardInfo"]) {
        DeleteCardCheckController *controller = (DeleteCardCheckController*) [segue destinationViewController];
        
        NSLog(@"%@",self.cardInfo);
        controller.passwordAndInfos = [self.cardInfo mutableCopy];
        return;
    }
}


@end
